<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>home</title>
	<link rel="stylesheet" type="text/css" href="${ctx}/themes/gray/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/script/jqgrid/css/jquery-ui-1.8.2.custom.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/script/jqgrid/css/ui.jqgrid.css">

	<script type="text/javascript" src="${ctx}/script/jquery.min.js"></script>
	<script type="text/javascript" src="${ctx}/script/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${ctx}/script/jqgrid/js/i18n/grid.locale-cn.js"></script>
	<script type="text/javascript" src="${ctx}/script/jqgrid/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" src="${ctx}/script/lhgdialog/lhgdialog.min.js?s=facebook"></script>
	
	<style>
	.altclass{
		background: #eeefff;
	}
	</style>

	<script type="text/javascript">
	<!--
		var dg = frameElement.lhgDG;
		dg.addBtn( 'ok', '保存', function(){ 
			gnsqSubmit();
		});
	
		$(function(){
			var jgbh = 	$("#jgbh").val();
			var czyid = $("#czyid").val();
			var params = {
				"jgbh" : jgbh,
				"czyid" : czyid
			};
			var actionUrl = "ywjsList.action";
			$.ajax({
				url : actionUrl,
				data : params,
				dataType : "json",
				cache : false,
				error : function(textStatus, errorThrown) {
					alert("系统ajax交互错误: " + textStatus);
				},
				success : function(data, textStatus) {
					if (data.ajaxResult == "success") {
						//alert(data.jgbh + data.czyid + data.selectedCzlb + data.gridModel);
						$("#gridTable").jqGrid({
							data: data.gridModel,
                			datatype: 'local',
							height: 400,
							width: 350,
						   	colNames:['ID','角色名称'],
						   	colModel:[
						   		{name:'ID', index:'ID',width:55,align:'center',sortable:false,hidden:true},
						   		{name:"LBMC",width:80,align:'center',sortable:false}
						   	],
						   	jsonReader: {
								root:"gridModel",
								repeatitems : false
							},
						    viewrecords: true,
						    sortname: 'id',
						    multiselect: true,
						    altRows:true,//隔行变色
						    altclass:'altclass',
						    loadComplete: function(){
						    	var selectedCzlb = data.selectedCzlb;
						    	if(selectedCzlb != null && selectedCzlb.length > 0) {
						    		//var rowData = $("#gridTable").jqGrid("getRowData");
						    		var dataIDs = $("#gridTable").jqGrid('getDataIDs');
									for(var i = 0; i < dataIDs.length; i++) {
										var rowData = $("#gridTable").jqGrid("getRowData",dataIDs[i]);
										for(var j = 0; j < selectedCzlb.length; j++) {
											if(rowData.ID == selectedCzlb[j].LBID) {
												$("#gridTable").jqGrid('setSelection',dataIDs[i]);
											}
										}
									}
						    	}
							}
						});
						$("#gridTable").jqGrid('navGrid','#gridpager',{edit:false,add:false,del:false,search:false,refresh:false});
					} else {
						alert("加载失败，请重试！");
					}
				}
			});
		});
		
		function gnsqSubmit() {
			var selr = jQuery('#gridTable').jqGrid('getGridParam','selarrrow');
			if(selr.length) {
				var ids = "";
				for(var i = 0; i < selr.length; i++) {
					ids += $('#gridTable').jqGrid('getCell',selr[i],'ID') + ",";
				}
				ids = ids == "" ? ids : ids.substring(0,ids.length-1);
				var params = {
					"ids" : ids
				};
				var actionUrl = "saveJgryQx.action";
				$.ajax({
					url : actionUrl,
					data : params,
					dataType : "json",
					cache : false,
					error : function(textStatus, errorThrown) {
						alert("系统ajax交互错误: " + textStatus);
					},
					success : function(data, textStatus) {
						if (data.ajaxResult == "success") {
							new dg.curWin.$.dialog({id:'2',title:'信息提示页面',page:'${ctx}/success.jsp',rang:true,iconTitle:false}).ShowDialog();
							dg.cancel();
						} else {
							alert("操作失败，请重试！");
						}
					}
				});
			} else {
				alert("至少选择一条记录！");
			}
			return true;
		}
	//-->	
	</script>
</head>
<body style="margin:1px">
<form id="form">
	<input type="hidden" id ="jgbh" name="jgbh" value="${jgbh}">
	<input type="hidden" id ="czyid" name="czyid" value="${czyid}">
	<table id="gridTable"></table>
</form>
</body>
</html>